package com.itxx.homeWork.demo4;

import com.itxx.homeWork.Student1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Reverse {
    // 服务器端:
    //  接收到这个数据之后,进行反序列化,将学生排序信息打印到控制台.
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ServerSocket serverSocket = new ServerSocket(54564);
        Socket socket = serverSocket.accept();

        //创建io流接受网络传输的数据
        BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("studentcopy.txt"));
        //创建反序列化数组


        int len;
        byte[] bytes = new byte[1024];
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
            bos.flush();

        }
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\develop\\workspace\\Advance_Code\\student.txt"));
        Student1 ss;
        while ((ss = (Student1) ois.readObject()) != null) {
            System.out.println(ss);
        }

    }
}
